package dao

import (
	"ssims/models"
)

func GetAllRandp(randp map[string]interface{}) (error, []models.Randp, int64) {
	var randpData []models.Randp
	page := randp["page"].(int)
	pageSize := randp["limit"].(int)
	//searchName := randp["searchName"].(string)
	var total int64
	err := db.Table("randp").Select("randp_no, randp_time, randp_level, student_name,  randp_describe, update_time").Where("is_del = false").Order("randp_no ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&randpData).Error
	return err, randpData, total
}
func AddRandp(randp models.Randp) error {
	err := db.Table("randp").Select("student_name", "randp_no", "randp_time", "randp_level", "randp_describe", "update_time").Create(&randp).Error
	return err
}

func UpdateRandp(randp models.Randp) error {
	err := db.Table("randp").Where("student_name = ?", randp.StudentName).Updates(&randp).Error
	return err
}

func DelRandp(id string) error {
	err := db.Table("randp").Where("randp_no = ?", id).Update("is_del", true).Error
	return err
}
